package com.kingschan.jeasytag.sql.sqlparse;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import com.kingschan.jeasytag.enums.DbType;
import com.kingschan.jeasytag.sql.JdbcTemplete;
/**
 * date:2013-07-10
 * @author kingschan
 *
 */
public class SqlMetaData {

	public static Map<String, Object> getColumnMetaData(String sql,DbType dbtype,Connection con,Object...objects) throws Exception{
		Map<String, Object> map = null;	
		Statement sm =con.createStatement();
		GenericSelectParse sp = new GenericSelectParse(sql, dbtype);
		sp.paginationLimit(1, 1);
		ResultSet rs=sm.executeQuery(sp.toString());
		ResultSetMetaData  rsmd;
		while (rs.next()) {
			  rsmd =rs.getMetaData();
			 map = new HashMap<String, Object>();
			for (int i = 1; i <=rsmd.getColumnCount(); i++) {				
				map.put(rsmd.getColumnName(i), rsmd.getColumnClassName(i));
				//System.out.println("字段名："+rsmd.getColumnName(i)+"\t\t数据库类型:"+ rsmd.getColumnTypeName(i)+"\t\tJAVA类名:\t"+rsmd.getColumnClassName(i));
			}
				
		}
		JdbcTemplete.closeDB(rs, sm, con);
		return map;
		
	}
}
